package com.suoluo.zenadmin.controllers.portal.trip;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.annotation.Resource;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Intercepted;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import org.springframework.web.multipart.MultipartFile;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.common.GeometryUtil;
import com.suoluo.zenadmin.common.GeometryUtil.TrafficEnum;
import com.suoluo.zenadmin.common.StringUtil;
import com.suoluo.zenadmin.common.SystemType;
import com.suoluo.zenadmin.common.UBB;
import com.suoluo.zenadmin.common.file.ImageUtils;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.service.InfoService;
import com.suoluo.zenadmin.service.dest.DestFeatureCategoryService;
import com.suoluo.zenadmin.service.dest.DestTrafficService;
import com.suoluo.zenadmin.service.trip.TripService;
import com.suoluo.zenadmin.vo.BaseInfoVO;
import com.suoluo.zenadmin.vo.dest.DestFeatureCategoryVO;
import com.suoluo.zenadmin.vo.dest.DestTraffic2VO;
import com.suoluo.zenadmin.vo.friend.FriendItemVO;
import com.suoluo.zenadmin.vo.trip.TripDailyFormVO;
import com.suoluo.zenadmin.vo.trip.TripDailyLocationsVO;
import com.suoluo.zenadmin.vo.trip.TripDailyVO;
import com.suoluo.zenadmin.vo.trip.TripFlightFormVO;
import com.suoluo.zenadmin.vo.trip.TripFlightVO;
import com.suoluo.zenadmin.vo.trip.TripLocationVO;
import com.suoluo.zenadmin.vo.trip.TripTripdestsVO;
import com.suoluo.zenadmin.vo.trip.TripVO;
import com.suoluo.zenadmin.vo.trip.TripdestVO;
import com.suoluo.zenadmin.vo.trip.UpdateTripDailyLocationVO;
import com.suoluo.zenadmin.vo.trip.UpdateTripStepRespVO;
import com.suoluo.zenadmin.vo.trip.UpdateTripStepVO;
import com.suoluo.zenadmin.vo.trip.UpdateTripTripdestVO;

@Path("")
public class TripController {

	@Resource(name="tripService")
	private TripService tripService;
	
	@Resource(name="categoryService")
	private DestFeatureCategoryService categoryService;
	
//	@Resource(name="destService")
//	private DestService destService;
//	
	@Resource(name="infoService")
	private InfoService infoService;
	
	@Resource(name="destTrafficService")
	private DestTrafficService destTrafficService;
	
//	private static final String TRIP_KEY = "$$zentravel.cn.TRIP_KEY";
	
	/**
	 * 编辑行程
	 * @param inv
	 * @param tripId 如果行程ID是0，则是重新编辑一条新的行程
	 * @return
	 */
	@Get("edit/add-destination")
	public String showAddDestination(Invocation inv, @Param("tid") int tripId){
		//1.将行程的关联的目的地查询出来
		//行程状态在第一步保存中设置为编辑状态
		if (tripId != 0){
			List<TripTripdestsVO> tripTripdests = tripService.findTripTripdestsByTripId(tripId); 
			inv.addModel("tripTripdests",tripTripdests);
			TripVO trip = tripService.findTripById(tripId);
			inv.addModel("trip",trip);
		}
		//2.将所有的目的地查询出来，给用户继续添加目的地
		List<TripdestVO> tripdests = tripService.findAuditedTripdests();
		inv.addModel("tripdests", tripdests);
		return "add_destination";
	}
	
	@JSON
	@Post("edit/add-destination")
	public Object addDestination(Invocation inv,UpdateTripStepVO stepVO){
		UpdateTripTripdestVO updateVO = stepVO.buildUpdateTripTripdest();
		tripService.updateTripTripdests(updateVO);
		UpdateTripStepRespVO resp = new UpdateTripStepRespVO();
		resp.setResultCode(CommonResp.SUCCESS_CODE);
		String nextURL = inv.getRequestPath().getCtxpath()+"/trip/edit/add-location?tid="+updateVO.getTripId();
		resp.setNextURL(nextURL);
		return resp;
	}
	
	@Get("edit/add-location")
	public String showAddLocation(Invocation inv,@Param("tid") int tripId){
		TripVO trip = tripService.findTripById(tripId);
		if (trip == null){
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination";
		}
		inv.addModel("trip",trip);
		//查询当前已经添加的想去的地方
		List<TripDailyVO> tripDailys =  tripService.findTripDailiyAndLocations(tripId);
		inv.addModel("tripDailys",tripDailys);
		
		//查询该行程已经添加的目的地
		List<TripTripdestsVO> tripTripdests = tripService.findTripTripdestsByTripId(tripId); 
		inv.addModel("tripTripdests",tripTripdests);
		return "add_location";
	}
	
	@JSON
	@Post("edit/add-location")
	public Object showAddLocation(Invocation inv,UpdateTripStepVO stepVO){
		
		UpdateTripDailyLocationVO updateVO = stepVO.buildUpdateTripDailyLocation();
		tripService.updateTripDailyLocations(updateVO);
		UpdateTripStepRespVO resp = new UpdateTripStepRespVO();
		resp.setResultCode(CommonResp.SUCCESS_CODE);
		String nextURL = null;
		if (stepVO.isNext()){
			nextURL = inv.getRequestPath().getCtxpath()+"/trip/edit/sort?tid="+updateVO.getTripId();
		} else {
			nextURL = inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination?tid="+updateVO.getTripId();
		}
		
		resp.setNextURL(nextURL);
		return resp;
	}
	
	@Get("edit/add-location/category")
	public String showCategory(Invocation inv,@Param("tdid") int tripdestId){
//		List<TripFeatureVO> categoryList = destService.findListFeatureByDestId(destId);\
		List<DestFeatureCategoryVO> categoryList = tripService.findTripdestCategorys(tripdestId);
		inv.addModel("categoryList",categoryList);
		inv.addModel("tripdestId",tripdestId);
		return "add_location_category";
	}
	
	@Get("edit/add-location/locations")
	public String showLocations(Invocation inv,@Param("tdid") int tripdestId,@Param("cid") int categoryId){
		
//		List<DestFeatureItem2VO> locations = (featureId);
		List<TripLocationVO> locations = tripService.findAuditedTripLocations(tripdestId, categoryId);
		inv.addModel("locations",locations);
		return "add_location_locations";
	}
	
	
	@Get("edit/sort")
	public String showTripSort(Invocation inv,@Param("tid") int tripId){
		if (tripId == 0) {
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination";
		}
		TripVO trip = tripService.findTripById(tripId);
		if (trip == null){
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination";
		}
		inv.addModel("trip",trip);
		List<TripDailyVO> tripDailys =  tripService.findTripDailiyAndLocations(tripId);
		inv.addModel("tripDailys",tripDailys);
		return "eidt_trip_sort";
	}
	
	@JSON
	@Post("edit/sort")
	public Object showTripSort(Invocation inv,UpdateTripStepVO stepVO){
		
		UpdateTripDailyLocationVO updateVO = stepVO.buildUpdateTripDailyLocation();
		tripService.updateTripSort(updateVO);
		UpdateTripStepRespVO resp = new UpdateTripStepRespVO();
		resp.setResultCode(CommonResp.SUCCESS_CODE);
		String nextURL = null;
		if (stepVO.isNext()){
			nextURL = inv.getRequestPath().getCtxpath()+"/trip/edit/preview?tid="+updateVO.getTripId();
		} else {
			nextURL = inv.getRequestPath().getCtxpath()+"/trip/edit/add-location?tid="+updateVO.getTripId();
		}
		
		resp.setNextURL(nextURL);
		return resp;
	}
	
	/**
	 * 行程预览，用于预览行程和行程第四步的展示
	 * @param inv
	 * @param tripId
	 * @return
	 */
	@Get("edit/preview")
	public String showTripPreview(Invocation inv,@Param("tid") int tripId){
		//1.查询行程
		TripVO trip = tripService.findTripById(tripId);
		if (trip == null) {
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination";
		}
		inv.addModel("editor",Boolean.valueOf(true));
		String summary = trip.getSummary();
		trip.setSummary(UBB.decode(summary));
		inv.addModel("trip",trip);
		//2.查询行程天和天的地点
		List<TripDailyVO> dailys = tripService.findTripDailys(tripId);
		if (dailys == null || dailys.isEmpty()){
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-location?tid="+tripId;
		}
		inv.addModel("dailys", dailys);
		Map<Integer,TripDailyVO> dailyMap = new HashMap<Integer, TripDailyVO>();
		for (TripDailyVO daily : dailys){
			dailyMap.put(daily.getDailyId(), daily);
		}
		TripDailyLocationsVO hotel1 = null;
		TripDailyLocationsVO hotel2 = null;
		List<TripDailyLocationsVO> locations = tripService.findTripLocations(tripId);
		for (TripDailyLocationsVO loc : locations) {
			////行程的两个酒店
			if (loc.getCategoryId() == SystemType.TRIP_CATEGORY_HOTEL){
				if (hotel1 == null){
					hotel1 = loc;
				} else if (hotel2 == null){
					if (loc.getLocationId() != hotel1.getLocationId()){
						hotel2 = loc;
					}
				}
			}
			TripDailyVO daily = dailyMap.get(loc.getDailyId());
			//天所经过的地点
			daily.addTripLocation(loc);
			//天所经过的目的地
			TripdestVO tripdest = new TripdestVO();
			tripdest.setDestId(loc.getDestId());
			tripdest.setName(loc.getDestName());
			tripdest.setTripdestId(loc.getTripdestId());
			daily.addTripdest(tripdest);
		}
		inv.addModel("hotel1",hotel1);
		inv.addModel("hotel2",hotel2);
		
		//3.查询行程的航班
		List<TripFlightVO> flights = tripService.findTripFights(tripId);
		TripFlightVO goFlight = null;
		TripFlightVO backFlight = null;
		for (TripFlightVO flight : flights){
			if (goFlight != null && backFlight != null){
				break;
			}
			if (flight.getBack() == SystemType.BIT_TRUE){
				if (backFlight == null){
					backFlight = flight;
				}
			} else {
				if (goFlight == null){
					goFlight = flight;
				}
			}
		}
		inv.addModel("goFlight", goFlight);
		inv.addModel("backFlight",backFlight);
		return "edit_preview";
	}
	
	/**
	 * 进入编辑行程页面
	 * @param inv
	 * @param tripId
	 * @return
	 */
	@Get("edit")
	public String showEidtTrip(Invocation inv,@Param("tid") int tripId){
		if (tripId == 0){
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination";
		}
		TripVO trip = tripService.findTripById(tripId);
		if (trip == null){
			return "r:" + inv.getRequestPath().getCtxpath()+"/trip/edit/add-destination";
		}
		inv.addModel("trip", trip);
		List<TripDailyVO> dailys = tripService.findTripDailys(tripId);
		inv.addModel("dailys", dailys);
		return "edit_trip";
	}
	@JSON
	@Post("edit/base")
	public Object saveTripBase(Invocation inv,TripVO tripVO){
		tripService.updateTripContent(tripVO);
		return CommonResp.SUCCESS;
	}
	
	@Get("edit/flight")
	public String showEditTripFlight(Invocation inv,@Param("tid") int tripId){
		//查询所有航空公司信息
		List<FriendItemVO> list = tripService.findListAirline();
		inv.addModel("list",list);
		//查询行程去程和返程的航班信息
		List<TripFlightVO> flights = tripService.findTripFights(tripId);
		inv.addModel("flights",flights);
		inv.addModel("tripId",tripId);
		return "edit_trip_flight";
	}
	@JSON
	@Post("edit/flight")
	public Object saveTripFlight(TripFlightFormVO flightVO){
		tripService.saveFlight(flightVO);
		return CommonResp.SUCCESS;
	}
	
	@Get("edit/daily")
	public String showEidtTripDaily(Invocation inv,@Param("tid") int tripId,@Param("did")int dailyId){
		//查询每天行程信息
		TripDailyVO daily = tripService.findTripDailyById(dailyId);
		inv.addModel("daily",daily );
		//查询每天行程下的自定义地点信息
		List<TripDailyLocationsVO> locations = tripService.findDailyLocations(dailyId);
		inv.addModel("locations",locations);
		//初始化类别接口
		List<DestFeatureCategoryVO> category = categoryService.findAllLeafCategory();
		DestFeatureCategoryVO select = new DestFeatureCategoryVO();
		select.setFeatureCategoryName("请选择类别");
		category.add(0,select);
		inv.addModel("category",category);
		return "edit_trip_daily";
	}
	@JSON
	@Post("edit/daily")
	public Object updateTripDaily(TripDailyFormVO dailyVO){
		//保存每天行程信息和每天关联的自定义地点信息
		tripService.updateTripDaily(dailyVO);
		return CommonResp.SUCCESS;
	}
	
	@Intercepted(deny="trip")
	@Get("{tid:[0-9]+}")
	public String showTrip(Invocation inv,@Param("tid") int tripId)
	{
		//1.查询行程
		TripVO trip = tripService.findTripById(tripId);
		//行程不存在
		if (trip == null) {
			return "r:" + inv.getRequestPath().getCtxpath()+"/classify/trip";
		}
		String summary = trip.getSummary();
		trip.setSummary(UBB.decode(summary));
		inv.addModel("trip",trip);
		//2.查询行程天和天的地点
		List<TripDailyVO> dailys = tripService.findTripDailys(tripId);
		
		
		Map<Integer,TripDailyVO> dailyMap = new HashMap<Integer, TripDailyVO>();
		for (TripDailyVO daily : dailys){
			
			String content = UBB.decode(daily.getContent());
			daily.setContent(content);
			dailyMap.put(daily.getDailyId(), daily);
		}
		inv.addModel("dailys", dailys);
		TripDailyLocationsVO hotel1 = null;
		TripDailyLocationsVO hotel2 = null;
		List<TripDailyLocationsVO> locations = tripService.findTripLocations(tripId);
		for (TripDailyLocationsVO loc : locations) {
			////行程的两个酒店
			if (loc.getCategoryId() == SystemType.TRIP_CATEGORY_HOTEL){
				if (hotel1 == null){
					hotel1 = loc;
				} else if (hotel2 == null){
					if (loc.getLocationId() != hotel1.getLocationId()){
						hotel2 = loc;
					}
				}
			}
			TripDailyVO daily = dailyMap.get(loc.getDailyId());
			//天所经过的地点
			daily.addTripLocation(loc);
			//天所经过的目的地
			TripdestVO tripdest = new TripdestVO();
			tripdest.setDestId(loc.getDestId());
			tripdest.setName(loc.getDestName());
			tripdest.setTripdestId(loc.getTripdestId());
			daily.addTripdest(tripdest);
		}
		inv.addModel("hotel1",hotel1);
		inv.addModel("hotel2",hotel2);
		
		//3.查询行程的航班
		List<TripFlightVO> flights = tripService.findTripFights(tripId);
		TripFlightVO goFlight = null;
		TripFlightVO backFlight = null;
		for (TripFlightVO flight : flights){
			if (goFlight != null && backFlight != null){
				break;
			}
			if (flight.getBack() == SystemType.BIT_TRUE){
				if (backFlight == null){
					backFlight = flight;
				}
			} else {
				if (goFlight == null){
					goFlight = flight;
				}
			}
		}
		inv.addModel("goFlight", goFlight);
		inv.addModel("backFlight",backFlight);
		return "trip";
	}
	
	@Intercepted(deny="trip")
	@Get("location/{lid:[0-9]+}")
	public String showTripLocation(Invocation inv,@Param("lid") int locationId){
		TripLocationVO location = tripService.findTripLocationById(locationId);
		
		//如果该地点不是自定义地点，则需要查询详细的描述信息
		if (location.getCustom() != SystemType.BIT_TRUE){
			StringBuilder content = new StringBuilder();
			//如果该地点是交通，则需要查询该类型的交通信息
			if (location.getCategoryId() == SystemType.TRIP_CATEGORY_TRAFFIC){
				List<DestTraffic2VO> traffics = destTrafficService.findTrafficEntity(location.getDataId());
				for (DestTraffic2VO traffic : traffics){
					String name = traffic.getName();
					String trafficPara = UBB.decode(traffic.getContent());
					if (!StringUtil.isEmpty(name)){
						content.append(name).append("</br>");
					}
					content.append(trafficPara);
				}
			} else {
				List<BaseInfoVO> infos = null;
				if (location.getCategoryId() == SystemType.TRIP_CATEGORY_HOTEL){
					infos = infoService.findBaseInfos(location.getRelId(),SystemType.INFO_HOTEL);
				} else {
					infos = infoService.findBaseInfos(location.getDataId(),SystemType.INFO_DEST_FEATURE_ITEM);
				}
				if (infos != null){
					for (BaseInfoVO info : infos){
						String name = StringUtil.buildCompleteName(info.getZhname(), info.getEnname());
						String para = UBB.decode(info.getContent());
						if (!StringUtil.isEmpty(name)){
							content.append(name).append("</br>");
						}
						content.append(para);
					}
				}
			}
			location.setContent(content.toString());
		}
		inv.addModel("location",location);
		return "trip_location";
	}
	
	/**
	 * 
	 * @param tripId
	 * @return
	 */
	@Intercepted(deny="trip")
	@Get("{tid:[0-9]+}/detail")
	public String showTripdetail(Invocation inv,@Param("tid") int tripId,@Param("from") boolean eidtor){
		//1.查询行程
		TripVO trip = tripService.findTripById(tripId);
		
		//行程不存在
		if (trip == null) {
			return "r:" + inv.getRequestPath().getCtxpath()+"/classify/trip";
		}
		inv.addModel("editor",Boolean.valueOf(eidtor));
		inv.addModel("trip",trip);
		//2.查询行程天和天的地点
		List<TripDailyVO> dailys = tripService.findTripDailys(tripId);
		inv.addModel("dailys", dailys);
		Map<Integer,TripDailyVO> dailyMap = new HashMap<Integer, TripDailyVO>();
		for (TripDailyVO daily : dailys){
			dailyMap.put(daily.getDailyId(), daily);
		}
		
		List<TripDailyLocationsVO> locations = tripService.findTripLocations(tripId);
		for (TripDailyLocationsVO loc : locations) {
			
			TripDailyVO daily = dailyMap.get(loc.getDailyId());
			//天所经过的地点
			daily.addTripLocation(loc);
			
			//天所经过的目的地
			TripdestVO tripdest = new TripdestVO();
			tripdest.setDestId(loc.getDestId());
			tripdest.setName(loc.getDestName());
			tripdest.setTripdestId(loc.getTripdestId());
			daily.addTripdest(tripdest);
		}
		
		//计算行程的的所经目的地，统计地点信息，地点之间的距离，交通方式等等
		Set<TripdestVO> allTripdests = new LinkedHashSet<TripdestVO>();
		Map<Integer,Integer> categoryStatMap = new HashMap<Integer, Integer>();
		
		TripDailyLocationsVO preLoc = null;
		for (TripDailyVO daily : dailys){
			//1.搜集途径的目的地
			List<TripdestVO> tripdests = daily.getTripdests();
			if (tripdests != null){
				allTripdests.addAll(tripdests);
			}
			double dailyDistance = 0;
			int dailyCostTime = 0;
			List<TripDailyLocationsVO> dailyLocations = daily.getTripDailyLocations();
			if (dailyLocations == null){
				continue;
			}
			for (TripDailyLocationsVO loc : dailyLocations){
				//2.统计地点的类别信息
				Integer categoryId = loc.getCategoryId();
				if (categoryStatMap.containsKey(categoryId)){
					int count = categoryStatMap.get(categoryId);
					categoryStatMap.put(categoryId, Integer.valueOf(count + 1));
				}else{
					categoryStatMap.put(categoryId, Integer.valueOf(1));
				}
				double distance = GeometryUtil.calcDistance(preLoc, loc);
				if (distance > 0){
					TrafficEnum traffic = GeometryUtil.selectTraffic(distance);
					int costTime = traffic.calcTime(distance);
					loc.setDistance(distance);
					loc.setCostTime(costTime);
					loc.setTrafficIcon(traffic.getIcon());
					dailyDistance += distance;
					dailyCostTime += (costTime + loc.getStayTime());
				}
				preLoc = loc;
			}
			daily.setCostTime(dailyCostTime);
			daily.setDistance(GeometryUtil.round(dailyDistance, 0));
		}
		StringBuilder destRoute = new StringBuilder();
		for (TripdestVO dest : allTripdests){
			destRoute.append(dest.getName()).append('-');
		}
		destRoute.deleteCharAt(destRoute.length() - 1);
		inv.addModel("destRoute",destRoute);
		
		StringBuilder categoryStat = new StringBuilder();
		for (Entry<Integer, Integer> entry : categoryStatMap.entrySet()){
			if (entry.getKey() == 0){
				continue;
			}
			DestFeatureCategoryVO category = categoryService.findDestFeatureCategoryById(entry.getKey());
			//过滤掉交通
			if (category == null){
				continue;
			}
			categoryStat.append(entry.getValue()).append("&nbsp;").append(category.getFeatureCategoryName()).append("&nbsp;&nbsp;");
		}
		inv.addModel("categoryStat",categoryStat);
		
		//查询行程的航班
		List<TripFlightVO> flights = tripService.findTripFights(tripId);
		List<TripFlightVO> goflights = new ArrayList<TripFlightVO>();
		List<TripFlightVO> backflights = new ArrayList<TripFlightVO>();
		for (TripFlightVO flight : flights){
			if (flight.getBack() == SystemType.BIT_TRUE){
				backflights.add(flight);
			} else {
				goflights.add(flight);
			}
		}
		inv.addModel("goflights", goflights);
		inv.addModel("backflights",backflights);
		return "trip_detail";
	}
	/**
	 * 保存图片信息
	 */
	@JSON
	@Post("saveimage")
	public Object uploadTripImage(Invocation inv,MultipartFile file,@Param("tripId")int tripId)
	{

		//验证上传文件的大小
		if (file == null || file.getSize() == 0){
			return new CommonResp(CommonResp.FAIL_CODE,"图片没有数据");
		}
		long size = file.getSize();
		if (size > (350 * 1024)) {
			return new CommonResp(CommonResp.FAIL_CODE,"图片太大，不能超过350KB");
		}
		//验证上传文件的类型,正确类型：image/jpeg,video/x-ms-wmv
		try {
			InputStream input = file.getInputStream();
			if(!ImageUtils.isValidImage(input))
			{
				return new CommonResp(CommonResp.FAIL_CODE,"图片类型不对,只支持JPG|PNG|GIF");
			}
		} catch (IOException e) {
			return CommonResp.FAIL;
		}
		//String name = ossService.putImage(file);
		//更新行程的图片信息到数据库
		tripService.updateTripImage(tripService.findTripById(tripId), file);
		//返回json格式数据@json:{resultCode:1003}
		return CommonResp.SUCCESS;
	}	
	
	/******保存行程描述、航空、行程封面、每天行程的信息*********/
	@JSON
	@Post("delete/flight")
	public Object deleteFlight(@Param("id")int flightId){
		tripService.deleteFlight(flightId);
		return CommonResp.SUCCESS;
	}
	
	/**
	 * 保存自定义地点的图片信息
	 */
	@JSON
	@Post("save/location/image")
	public Object uploadLocationImage(Invocation inv,MultipartFile file,@Param("lid")int locationId)
	{

		//验证上传文件的大小
		if (file == null || file.getSize() == 0){
			return new CommonResp(CommonResp.FAIL_CODE,"图片没有数据");
		}
		long size = file.getSize();
		if (size > (350 * 1024)) {
			return new CommonResp(CommonResp.FAIL_CODE,"图片太大，不能超过350KB");
		}
		//验证上传文件的类型,正确类型：image/jpeg,video/x-ms-wmv
		try {
			InputStream input = file.getInputStream();
			if(!ImageUtils.isValidImage(input))
			{
				return new CommonResp(CommonResp.FAIL_CODE,"图片类型不对,只支持JPG|PNG|GIF");
			}
		} catch (IOException e) {
			return CommonResp.FAIL;
		}
		
		//更新行程自定义地点图片信息到数据库
		tripService.updateLocationImage(locationId, file);
		//返回json格式数据@json:{resultCode:1003}
		return CommonResp.SUCCESS;
	}
	/**
	 * 发布行程最后一步  更新行程为可用状态
	 * @param tripId
	 */
	@Get("edit/finish")
	public String updateTripStatus(Invocation inv,@Param("tid")int tripId){
		tripService.updateTripStatus(tripId);
		return "r:" + inv.getRequestPath().getCtxpath()+"/classify/trip";
	}
}
